package com.ly.controller;

import com.ly.dao.PersonDao;
import com.ly.entity.Person;
import com.ly.entity.PersonDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class HelloController {

    int b=0;
    int v=0;
    @Autowired
    PersonDao personDao;

    @RequestMapping("/hello")
    public  String hello(){
        System.out.println("fdjfdfdfd");
        return "test";
    }
    @RequestMapping("/save")
    public String save(){
        Person person = new Person();
        person.setEmail("513422479@11.com");
        person.setId(1);
        person.setName("liyu");
        person.setStatus(1);
        personDao.addPerson(person);
        return "test";
    }

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public String get(){
        List<Person> list= personDao.getAllPerson();

       int  aaaa =0;
        for (Person person: list) {
            System.out.println(person.getName());
        }

        return "test";
    }

    @RequestMapping(value = "/all1",method = RequestMethod.GET)
    public String get1(){
        Person person= personDao.getPerson("1");

        System.out.println(person.getName());

        return "test";
    }

    @RequestMapping(value = "/all2",method = RequestMethod.GET)
    public String get2(){
        personDao.get();

        //System.out.println(person.getName());

        return "test";
    }

    @RequestMapping(value = "/all3",method = RequestMethod.GET)
    public String get3(){
        personDao.get1();

        //System.out.println(person.getName());

        return "test";
    }

    @RequestMapping(value = "/all4",method = RequestMethod.GET)
    public String get4(){
        List<PersonDTO> list= personDao.get2();

        for (PersonDTO p: list) {
            System.out.println("email="+p.getEmail() +"  name="+ p.getName() +" childhoodName;" + p.getChildhoodName());
        }
        //System.out.println(person.getName());

        return "test";
    }
}
